<%@page import="entities.Application"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%@page import="entities.AutoSite"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
Application app = (Application) request.getAttribute("app");
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
AutoSite autoSite = (AutoSite) request.getAttribute("autoSite");
String form = (String) request.getAttribute("form");
List<Category> categories = (List<Category>) request.getAttribute("categories");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />
    
<script type="text/javascript" src="/admin/js/site_form.js"></script>
<script type="text/javascript">
var appid = "<%=app.getId()%>";
</script>	
		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/site/list/<%=app.getId() %>">List Sites</a></li>
                	<li class="current"><a href="/admin/site/add/<%=app.getId() %>"><%=(form!=null&&form.equalsIgnoreCase("edit")) ? "Edit Site" : "Add New AutoSite" %></a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<% if (success != null) {%>
					<div class="notification msgsuccess">
                        <a class="close"></a>
                        <p><%=success %></p>
                    </div>
					<% } %>
                    <div class="contenttitle">
                    	<h2 class="form"><span><%=form.equalsIgnoreCase("add") ? "Add Site" : "Edit Site" %></span></h2>
                    </div><!--contenttitle-->
            
                    <form method="post" action="#" class="stdform" id="edit_site_form">
                    	
                        <p>
                        	<label>Sitemaps</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="url" id="s_url" value="<%=autoSite.getUrl() != null ? autoSite.getUrl() : "" %>" 
                            		<%=form.equalsIgnoreCase("add") ? "" : "readonly=\"readonly\"" %>>
                            	<% if (check.get("url") != null) { %>
									<label for="s_url" generated="true" class="error"><%=check.get("url") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Title Link</label>
                            <span class="field">
                            	<input type="text" class="mediuminput" name="regLink" id="s_regLink" value="<%=autoSite.getRegLink() != null ? autoSite.getRegLink() : "" %>">
                            	<% if (check.get("regLink") != null) { %>
									<label for="s_regLink" generated="true" class="error"><%=check.get("regLink") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Title</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="regTitle" id="s_regTitle" value="<%=autoSite.getRegTitle() != null ? autoSite.getRegTitle() : "" %>">
                            	<% if (check.get("regTitle") != null) { %>
									<label for="s_regTitle" generated="true" class="error"><%=check.get("regTitle") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Content</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="regContent" id="s_regContent" value="<%=autoSite.getRegContent() != null ? autoSite.getRegContent() : "" %>">
                            	<% if (check.get("regContent") != null) { %>
									<label for="s_regContent" generated="true" class="error"><%=check.get("regContent") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Remove</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="regRemove" id="s_regRemove" value="<%=autoSite.getRegRemove() != null ? autoSite.getRegRemove() : "" %>">
                            	<% if (check.get("regRemove") != null) { %>
									<label for="s_regRemove" generated="true" class="error"><%=check.get("regRemove") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Selector of Author</label>
                            <span class="field">
                            	<input type="text" class="longinput" name="regAuthor" id="s_regAuthor" value="<%=autoSite.getRegAuthor() != null ? autoSite.getRegAuthor() : "" %>">
                            	<% if (check.get("regRemove") != null) { %>
									<label for="s_regAuthor" generated="true" class="error"><%=check.get("regAuthor") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Time Schedule</label>
                            <span class="field">
                            	<select name="scheduleSite" id="schedule-site">
									<option value="60" <%=autoSite.getScheduleSite() == 60 ? "selected=\"selected\"" : "" %>>1 hour</option>
									<option value="120" <%=autoSite.getScheduleSite() == 120 ? "selected=\"selected\"" : "" %>>2 hour</option>
									<option value="180" <%=autoSite.getScheduleSite() == 180 ? "selected=\"selected\"" : "" %>>3 hour</option>
									<option value="360" <%=autoSite.getScheduleSite() == 360 ? "selected=\"selected\"" : "" %>>6 hour</option>
									<option value="720" <%=autoSite.getScheduleSite() == 720 ? "selected=\"selected\"" : "" %>>12 hour</option>
									<option value="1080" <%=autoSite.getScheduleSite() == 1080 ? "selected=\"selected\"" : "" %>>18 hour</option>
									<option value="1440" <%=autoSite.getScheduleSite() == 1440 ? "selected=\"selected\"" : "" %>>24 hour</option>
								</select>
                            	<% if (check.get("scheduleSite") != null) { %>
									<label for="s_scheduleSite" generated="true" class="error"><%=check.get("scheduleSite") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Category</label>
                            <span class="field">
                            	<select name="category" id="s_category">
                            		<% for (int i = 0; i < categories.size(); i++) { %>
                            		<option value="<%=categories.get(i).getId() %>" <%=autoSite.getCategory().equalsIgnoreCase(categories.get(i).getId()) ? "selected=\"selected\"" : "" %>><%=categories.get(i).getName() %></option>
                            		<% } %>
                            	</select>
                            	<% if (check.get("category") != null) { %>
									<label for="s_category" generated="true" class="error"><%=check.get("category") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Author Name</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="creator" id="s_creator" value="<%=autoSite.getCreator() != null ? autoSite.getCreator() : "" %>">
                            	<% if (check.get("creator") != null) { %>
									<label for="s_creator" generated="true" class="error"><%=check.get("creator") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Do you want translate?</label>
                            <span class="field">
                            	<select name=isTranslate>
                            		<option value="true" <%=autoSite.isTranslate() ? "selected=\"selected\"" : "" %>>Yes</option>
                            		<option value="false" <%=!autoSite.isTranslate() ? "selected=\"selected\"" : "" %>>No</option>
                            	</select>
                            	<% if (check.get("isTranslate") != null) { %>
									<label for="s_isTranslate" generated="true" class="error"><%=check.get("isTranslate") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="translate">
                        	<label>Source Language</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="language" id="s_language" value="<%=autoSite.getLanguage()%>">
                            	<% if (check.get("language") != null) { %>
									<label for="s_language" generated="true" class="error"><%=check.get("language") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="translate">
                        	<label>Translate Language</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="translate" id="s_translate" value="<%=autoSite.getTranslate()%>">
                            	<% if (check.get("translate") != null) { %>
									<label for="s_translate" generated="true" class="error"><%=check.get("translate") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label></label>
                            <span class="field">
                            	<a href="#popchecksite" class="popchecksite">Check info</a>
                            </span>
                        </p>
                        
                        <p class="stdformbutton">
                        	<button class="submit radius2">Submit</button>
                            <input type="reset" value="Reset" class="reset radius2">
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div>
        <div style="display: none">
			<div id="popchecksite">
				<div style="text-align: center; padding-top: 200px;">
					<h2>Loadding....</h2>
				</div>
			</div>
		</div>
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>